package knapsackProblem;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.joda.time.Instant;

public class Executor {

	public static void run(Set<knapsackProblem.Task> tasks,Instant startTime, Instant finishTime) throws Exception {
		ControlDecision controlDecision = new ControlDecision(tasks);

		ProperState properState = new ProperState();
		TimeInstant timeInstant = new TimeInstant(new Instant(startTime));

		List<almm.GeneralizedState> followingStates = new ArrayList<almm.GeneralizedState>();

		almm.GeneralizedState initialState = GeneralizedStateSet.getGeneralizedState(properState,
				timeInstant, finishTime, tasks.size());

		IndividualDiscreteProcess idp = new IndividualDiscreteProcess(
				initialState, finishTime, tasks.size(), 1);

		almm.GeneralizedState followingState = initialState;

		while (!followingState.isGoalState()
				&& !followingState.isNotAdmissibleState()) {
			idp = new IndividualDiscreteProcess(followingState,finishTime,tasks.size(),1);
			followingStates.add(followingState);
			followingState = idp.next(controlDecision, followingState);
		}
		if(followingState.isGoalState())
			System.out.println("Goal is reached");
		if(followingState.isNotAdmissibleState()) 
			System.out.println("Not admissible state is reached");
	}
}